<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: Muerzhi
  Date: 2023/12/25
  Time: 19:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
  //    String id=request.getParameter("id");
  String name=request.getParameter("newName");
  String author=request.getParameter("newAuthor");
  String house=request.getParameter("newHouse");
  String money=request.getParameter("newMoney");

  Class.forName("com.mysql.cj.jdbc.Driver");
  String url="jdbc:mysql://localhost:3306/library";
  String username="root";
  String password="17876724541";
  Connection conn = DriverManager.getConnection(url,username,password);

  String sql="INSERT INTO book(bookName,bookAuthor,bookHouse,bookMoney) values(?,?,?,?)";
  PreparedStatement ps =conn.prepareStatement(sql);
//    ps.setString(1,id);
  ps.setString(1,name);
  ps.setString(2,author);
  ps.setString(3,house);
  ps.setString(4,money);
  int i=ps.executeUpdate();
  if (i==1){
    out.println("<script>");
    out.println("alert('书籍《"+name+"》添加成功');");
    out.println("location.href='index.jsp#content2'");
    out.println("</script>");
  }else{
  out.println("<script>");
  out.println("alert('添加失败');");
  out.println("location.href='index.jsp#content2'");
  out.println("</script>");
}
  ps.close();
  conn.close();
%>
</body>
</html>
